package com.ak.jddemo;

import com.ak.jddemo.test.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

import java.io.IOException;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.util.Collections;
import java.util.Scanner;

/**
 * @author ak
 */
@SpringBootApplication
@EnableConfigurationProperties
@Slf4j
public class JddemoApplication {

    public static void main(String[] args) throws InterruptedException, IOException, URISyntaxException, ParseException {
        System.out.println("请输入商品id");
        Scanner scanner = new Scanner(System.in);
        Config.pid = scanner.next();
        SpringApplication.run(JddemoApplication.class, args);
        //读取cookie
        String cookie = SeckillService2.reader();
        if (cookie != null && cookie.contains("wlfstk")) {
            SeckillService2.COOKIE = Collections.singletonList(cookie);
            log.info("已登录");
        } else {
            //登录
            Login.login();
            SeckillService2.initCookie();
        }
        //添加购物车
        SeckillUtils.addCar();
        //初始化请求参数
        SeckillService2.preparation(SeckillService2.getOrderInfoHeader());
        SeckillService2.initSubData(HttpUrlConnectionUtil.getInitMsg(SeckillService2.getInitHeaders()));
        //判断是否开始抢购
        SeckillUtils.checkTime();
        //开始抢购
        SeckillService2.begin();
    }


}
